<template>
  <div>
    <!-- 基本信息 -->
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>基础信息</span>
      </div>
      <el-form label-width="120px" style="margin-bottom: 20px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划编号">
              <el-input placeholder="系统自动生成" disabled style="width: 410px"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划名称">
              <el-input v-model="scheme.patrolSchemeName"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划开始时间">
              <el-date-picker type="date" v-model="scheme.patrolSchemeOntime" placeholder="请选择开始日期"
                style="width: 410px"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划结束时间">
              <el-date-picker type="date" v-model="scheme.patrolSchemeUntime" placeholder="请选择结束日期"
                style="width: 490px"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="计划类型">
              <el-select style="width: 410px" v-model="scheme.patrolSchemeDaytypeId">
                <el-option v-for="item in schemeType" :value="item" :key="item">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="执行周期规则" style="width: 610px">
              <el-input v-model="display" @focus="rule = true">
                <el-button slot="append" icon="el-icon-search" @click="rule = true"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-col :span="12"><el-form-item label="执行周期描述">
                <el-input :rows="4" type="textarea" disabled style="width: 1100px"></el-input>
              </el-form-item></el-col>
          </el-col>
        </el-row>

        <el-form-item label="状态">
          <el-select v-model="scheme.patrolSchemeType" placeholder="请选择" style="width: 410px">

            <el-option v-for="item in schemeStatus" :key="item" :value="item" :label="item">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" style="width: 1100px" v-model="scheme.notas"></el-input>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="box-card">
      <!-- 点检人员 -->
      <div slot="header" class="clearfix">
        <span>点检人员</span>
      </div>
      <el-form label-width="120px" style="margin-bottom: 20px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="点检班组">
              <el-input v-model="scheme.patrolSchemeClass" placeholder="请输入" style="width: 410px"
                @focus="group = true"><el-button slot="append" icon="el-icon-search"
                  @click="group = true"></el-button></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="点检负责人">
              <el-input v-model="scheme.patrolSchemePerson" placeholder="请输入" style="width: 410px"
                @focus="clerk = true"><el-button slot="append" icon="el-icon-search"
                  @click="clerk = true"></el-button></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>点检明细</span>
      </div>
      <!-- 点检明细 -->
      <el-button-group>
        <el-button type="primary" @click="device = true;">添加</el-button>
        <el-button>移除</el-button>
      </el-button-group>

      <el-table :data="tableData" ref="registTable" style="width: 100%; margin-top: 20px;z-index:0"
      @selection-change="handelSelect">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="id" label="序号" width="50" align="center"></el-table-column>
        <el-table-column label="操作" width="70" align="center" fixed>
          <template slot-scope="scope">
            <el-button type="text" @click="handleView(scope.$index)">移除</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="numbering" label="设备编号" width="170" align="center"></el-table-column>
        <el-table-column prop="name" label="设备名称" align="center"></el-table-column>
        <el-table-column prop="model" label="规格型号" align="center"></el-table-column>
        <el-table-column prop="type" label="设备类型" align="center"></el-table-column>
        <el-table-column prop="brand" label="品牌" align="center"></el-table-column>
        <el-table-column prop="department" label="使用部门" align="center"></el-table-column>
        <el-table-column prop="location" label="存放位置" align="center"></el-table-column>
        <el-table-column prop="isCritical" label="是否拍照" align="center" width="150px">
          <template slot-scope="scope">
            <el-radio v-model="scope.row.isCritical" label="1">是</el-radio>
            <el-radio v-model="scope.row.isCritical" label="2">否</el-radio>
          </template>
        </el-table-column>
        <el-table-column prop="isScan" label="扫码登记" align="center" width="150px">
          <template slot-scope="scope">
            <el-radio-group v-model="scope.row.isScan">
              <el-radio label="1">是</el-radio>
              <el-radio label="2">否</el-radio></el-radio-group>
          </template></el-table-column>
        <el-table-column prop="inspectionPro" label="点检项目" align="center" width="150px"></el-table-column>
        <el-table-column prop="inspectionPro" label="操作" width="150px">
          <template slot-scope="scope">
            <a @click="getProject(scope.row)">添加</a>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card class="box-card" style="margin-bottom: 10%">
      <!--关联文件-->

      <div slot="header" class="clearfix">
        <span>关联文件</span>
      </div>
      <el-button-group style="margin-bottom: 20px">
        <el-upload ref="upload2" action="http://localhost:9289/maintenance/upload2" :on-change="handleUploadSuccess2"
          :on-success="cgong" :file-list="fileList" :auto-upload="false" :show-file-list="false"
          :before-upload="beforeUpload" :data="{ code: application }" multiple>
          <el-button type="primary">上传文档</el-button>
        </el-upload>
        <el-button @click="removeSelectedRows3">移除</el-button>
      </el-button-group>
      <el-table :data="documents" style="width: 100%" border @selection-change="handleSelectionChange2">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column prop="name" label="文件名"></el-table-column>
        <el-table-column prop="uploadDate" label="上传时间"></el-table-column>
        <el-table-column prop="uploader" label="上传者"></el-table-column>
        <el-table-column prop="size" label="文档大小"></el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button type="text" @click="removeRow3(scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 选择点检项目 -->
      <el-dialog v-model="project" :visible.sync="project" title="选择点检项目" style="width: 150%; margin-left: -25%">
        <el-divider></el-divider>
        <el-form>
          <el-row>
            <el-col :span="8">
              <el-form-item>
                <el-input placeholder="请输入点检项目名称/编号" style="width: 300px" v-model="condition1"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <el-select style="width: 300px; margin-left: -60px" placeholder="请选择点检部位" v-model="selectType">
                  <el-option v-for="item in ProjectType.data" :key="item" :label="item.dictLabel"
                    :value="item.dictLabel"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item>
                <el-input placeholder="请输入点检内容" style="width: 300px"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item style="text-align: right">
                <el-button>重置</el-button>
                <el-button>查询</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-table :data="inspectionProject.records" @selection-change="handleSelectionChange1" border="0" ref="refIns"
          style="width: 100%" align="center" sortable>
          <el-table-column type="selection" width="55" />
          <el-table-column label="序号" width="180" align="center" fixed>
            <template slot-scope="scope">
              {{ (currentPage - 1) * size + scope.$index + 1 }}
            </template></el-table-column>
          <el-table-column prop="pmtsName" label="点检项目名称" width="180" align="center"></el-table-column>
          <el-table-column prop="code" label="点检项目编号" width="180" align="center"></el-table-column>
          <el-table-column prop="pmtsPartId" label="点检分类" width="180" align="center">
          </el-table-column>
          <el-table-column prop="pmtsPartId" label="点检方法" width="180" align="center">
          </el-table-column>
          <el-table-column prop="pmtsMethod" label="点检内容" width="180" align="center"></el-table-column>
          <el-table-column prop="deviceInspectiontaskResult.resultName" label="判定结果类型" width="180"
            align="center"></el-table-column>
          <el-table-column prop="pmtsIsresult" label="判定结果选项" width="180" align="center"></el-table-column>
          <el-table-column prop="pmtsNotes" label="备注" width="180" align="center"></el-table-column>
        </el-table>
        <el-row style="text-align: right;margin-top: 20px">
          <el-pagination background layout="prev, pager, next, sizes, total" :total="this.inspectionProject.total"
            :page-size="this.inspectionProject.size" :sizes="this.inspectionProject.size" :page-sizes="pageselect"
            @size-change="handleSizeChange" :current-page="this.inspectionProject.current"
            @current-change="handleCurrentChange">
          </el-pagination>
        </el-row>
        <el-divider></el-divider>
        <div style="text-align: right">
          <el-button @click="clerk = false">取消</el-button>
          <el-button type="primary" @click="handleConfirm">确认</el-button>
        </div>
      </el-dialog>

      <!-- 选择设备 -->
      <el-dialog title="选择设备" :visible.sync="device" width="60%">
        <div>
          <el-input placeholder="请输入设备编号/名称/规格型号" v-model="searchInput"
            style="width: 20%; margin-right: 10px"></el-input>
          <el-select placeholder="请选择设备类型" v-model="selectedType" style="width: 20%; margin-right: 10px">
            <el-option label="生产设备" value="生产设备"></el-option>
          </el-select>
          <el-select placeholder="请选择使用部门" v-model="selectedDepartment" style="width: 20%; margin-right: 10px">
            <el-option label="生产部门" value="生产部门"></el-option>
          </el-select>
          <el-button type="primary" @click="handleSearch2">查询</el-button>
          <el-button @click="handleReset2">重置</el-button>
        </div>

        <el-table size="mini" :cell-style="{ padding: '0px' }" :row-style="{ height: '35px' }" :data="filteredData"
          style="width: 100%; margin-top: 20px" stripe ref="registTable2" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center"></el-table-column>
          <el-table-column prop="eid" label="序号" width="50" align="center"></el-table-column>
          <el-table-column prop="code" label="设备编号" width="170" align="center"></el-table-column>
          <el-table-column prop="name" label="设备名称" align="center"></el-table-column>
          <el-table-column prop="specifications" label="规格型号" align="center"></el-table-column>
          <el-table-column prop="deviceType" label="设备类型" align="center"></el-table-column>
          <el-table-column prop="brand" label="品牌" align="center"></el-table-column>
          <el-table-column prop="useDepartments" label="使用部门" align="center"></el-table-column>
          <el-table-column prop="storageLocation" label="存放位置" align="center"></el-table-column>
        </el-table>

        <el-pagination background layout="prev, pager, next, sizes, total" :total="this.data.data.total"
          :page-size="this.data.data.pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"
          style="margin-top: 20px" />

        <div slot="footer" class="dialog-footer">
          <el-button @click="handleCancel">取消</el-button>
          <el-button type="primary" @click="handleConfirm">确认</el-button>
        </div>
      </el-dialog>

      <!-- 执行周期规则 -->
      <el-dialog v-model="rule" :visible.sync="rule" style="width: 150%; margin-left: -25%">
        <span>选择执行结果</span>
        <el-divider></el-divider>
        <el-form>
          <el-row>
            <el-col :span="8">
              <el-form-item>
                <el-input placeholder="请输入规则名称" style="width: 300px" v-model="executionName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <el-select style="width: 300px; margin-left: -60px" v-model="ruleType">
                  <el-option v-for="item in ruleTypes" :key="item.value" :value="item.value"
                    :label="item.label"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <el-input placeholder="请输入执行间隔" style="width: 300px; margin-left: -120px"
                  v-model="executionInterval"></el-input>
              </el-form-item>
              <div style="text-align: right">
                <el-button>重置</el-button>
                <el-button>查询</el-button>
              </div>
            </el-col>
          </el-row>
        </el-form>
        <el-table ref="tableRef" :data="execution.records" @row-click="singleElection" highlight-current-row border>
          <el-table-column label="序号" width="55">
            <template slot-scope="scope">
              <span>{{ (page - 1) * size + scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="规则名称" prop="executionName" align="center">
          </el-table-column>
          <el-table-column label="执行规则类型" prop="executionType" align="center">
            <template slot-scope="scope">
              <el-span v-if="scope.row.executionType === '0'">小时</el-span>
              <el-span v-if="scope.row.executionType === '1'">周</el-span>
              <el-span v-if="scope.row.executionType === '2'">月</el-span>
              <el-span v-if="scope.row.executionType === '3'">季</el-span>
              <el-span v-if="scope.row.executionType === '4'">年</el-span>
            </template>
          </el-table-column>
          <el-table-column label="执行频率" prop="executionFrequency" align="center">
          </el-table-column>
          <el-table-column label="执行间隔" prop="executionInterval" align="center">
          </el-table-column>
          <el-table-column label="规则描述" prop="executionDescribe" align="center">
          </el-table-column>
        </el-table>

        <!-- Pagination -->
        <div style="text-align: right; margin-top: 10px">
          <el-pagination background layout="prev, pager, next, jumper,total" :total="this.execution.total"
            :page-size="this.execution.size" @current-change="handleCurrentChange" @size-change="handleSizeChange"
            :page-sizes="[10, 20, 30, 40, 50]">
          </el-pagination>
        </div>
        <el-divider></el-divider>
        <el-button @click="rule = false">取消</el-button>
        <el-button @click="ruleSumit()">确认</el-button>
      </el-dialog>

      <!-- 选择班组 -->
      <el-dialog v-model="group" :visible.sync="group" style="width: 80%; margin-left: 20%">
        <span>选择班组</span>
        <el-divider></el-divider>

        <el-form @submit.native.enter.prevent>
          <el-form-item>
            <el-input placeholder="请输入" v-model="condition" @keyup.enter.native="classSearch()">
              <i slot="suffix" class="el-icon-search"></i>
            </el-input>
          </el-form-item>
        </el-form>

        <el-table :data="classList.records" border stripe ref="tableRef1" @row-click="singleElection"
          highlight-current-row>
          <el-table-column label="序号" width="65" prop="classId" align="center">
          </el-table-column>
          <el-table-column label="班组名称" prop="className" align="center"></el-table-column>
          <el-table-column label="班组人数" align="center"></el-table-column>
        </el-table>
        <div style="text-align: right">
          <el-pagination background layout="prev, pager, next, jumper,total" :total="this.classList.total"
            :page-size="this.classList.size" @current-change="handleCurrentChange" @size-change="handleSizeChange"
            :page-sizes="[10, 20, 30, 40, 50]">
          </el-pagination>
        </div>
        <el-divider></el-divider>
        <div style="text-align: right">
          <el-button @click="group = false">取消</el-button>
          <el-button type="primary" @click="classSubmit">确认</el-button>
        </div>
      </el-dialog>

      <!-- 点检人 -->
      <el-dialog v-model="clerk" :visible.sync="clerk" style="width: 80%; margin-left: 20%">
        <span>{{ this.templateSelection.className }}_选择人员</span>
        <el-divider></el-divider>

        <el-form>
          <el-form-item>
            <el-input placeholder="请输入">
              <i slot="suffix" class="el-icon-search"></i>
            </el-input>
          </el-form-item>
        </el-form>
        <el-table ref="tableRef2" :data="userList" highlight-current-row @row-click="singleElection" border>
          <el-table-column label="序号">
            <template slot-scope="scope">
              {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="用户名" prop="userName"></el-table-column>
          <el-table-column label="姓名" prop="nickName"></el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize" @pagination="getList" />
        <el-divider></el-divider>
        <div style="text-align: right">
          <el-button @click="clerk = false">取消</el-button>
          <el-button type="primary" @click="clerkSubmit">确认</el-button>
        </div>
      </el-dialog>
    </el-card>
    <el-card class="position">
      <el-row :gutter="20">
        <el-col :offset="9" :span="6">
          <el-button @click="closeForm">关闭</el-button>
          <el-button type="primary" @click="confirmForm">确认</el-button>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import axios from "axios";
import { executionList } from "@/api/inspection/inspectionPlan";
import { listEquipment2, listEquipment, InsertAnnex } from "@/api/eastjet-maintenance/sb/sb";
import { classList } from "@/api/inspection/inspectionPlan";
import { listUser } from "@/api/system/user";
import { selectZi } from "@/api/eastjet-maintenance/type/type";
import { patroladd, detailadd, taskadd } from "@/api/eastjet-maintenance/spotcheck/spotcheckPlan";
import { upload } from "@/api/inspection/inspectionPlan";

export default {
  data() {
    return {
      rule: false,
      group: false,
      clerk: false,
      device: false,
      project: false,
      currentPage: 1,
      proPage: 1,
      selectType: "",
      sizes: 10,
      pageSize: 10,
      condition1: "",
      data: [],
      multipleSelection: [],
      execution: [],
      classList: [],
      userList: [],
      filteredData: [],
      filteredData2: [],
      tableData: [],
      inspectionProject: [],
      ProjectType: [],
      mulitiSelect: [],
      selectChange: [],
      ruleType: "",
      executionName: "",
      executionInterval: "",
      templateSelection: "",
      className: "",
      page: 1,
      page1: 1,
      size1: 2,
      size: 2,
      total: 0,
      schemeType: ["日计划", "周计划", "月计划", "季计划", "年计划"],
      schemeStatus: ["未开始", "待审核", "已审核", "待实施", "实施中", "已关闭", "驳回"],
      pageselect: [10, 20, 30, 40, 50],
      documents: [],
      document: {
        name: "",
        uploader: "",
        uploadDate: new Date().toLocaleDateString(),
        size: "",
      },
      fileList2: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined
      },
      condition: "",
      tableRef: "",
      tableRef1: "",
      ruleTypes: [
        { value: 0, label: "小时" },
        { value: 1, label: "日" },
        { value: 2, label: "周" },
        { value: 3, label: "月" },
        { value: 4, label: "季" },
        { value: 5, label: "年" },
      ],
      detail: {
        isCritical: '1',
        isScan: '1',
        deviceCode: "",
        inspectionCode: "",
      },
      scheme: {
        patrolSchemeName: "",
        patrolSchemeType: "",
        patrolSchemeDaytypeId: "",
        patrolSchemeRule: "",
        patrolSchemeOntime: "",
        patrolSchemeUntime: "",
        patrolSchemePerson: "",
        patrolSchemeClass: "",
        notas: "",
        selectChange: [],
        insertName: this.$store.state.user.username,

      },
      zhi: "sys_inpectionpro_type",

    };
  }, computed: {
    display() {
      return this.templateSelection.executionName;
    }
  }, mounted() {
    this.init();
    this.groupSearch();
    this.user();
    this.projectlist();
    selectZi(this.zhi).then((res) => {
      this.ProjectType = res.data;
      console.log("字典", this.ProjectType);
    });

  },
  methods: {
    validateForm() {
      const fields = [
        'patrolSchemeName',
        'patrolSchemeType',
        'patrolSchemeDaytypeId',
        'patrolSchemeRule',
        'patrolSchemeOntime',
        'patrolSchemeUntime',
        'patrolSchemePerson',
        'patrolSchemeClass',
        'notas',
      ];



      for (const field of fields) {
        if (!this.scheme[field]) {
          return false;
        }
      }

      if (this.tableData.length == 0) {
        console.log(this.tableData.length);
        return false;
      }
      if(this.mulitiSelect.length == 0){
        console.log(this.mulitiSelect.length);
        return false;
      }
      if(this.documents.length == 0){
        return false;
      }
      return true;
    },  
    init() {
      executionList(this.page, this.size, this.condition1)
        .then((res) => {
          this.execution = res.data;
          console.log(res.data);
        })
        .catch((res) => { console.log(res); });
      this.getList();
    },
    getProject(row) {
      console.log("code", row);
      this.project = true;
      this.projectlist();
    },
    projectlist() {
      axios
        .get("http://localhost:9286/spotcheckPro/selectPmts", {
          params: { page: this.proPage, size: this.sizes, condition: this.condition },
        })
        .then((res) => {
          this.inspectionProject = res.data;
          console.log(res.data);

        })
        .catch((err) => {
          console.log(err);
        });
    },
    handelSelect(val) {
      this.selectChange = val;
      console.log(val);
    
    },
    handleSelectionChange1(val) {
      this.mulitiSelect = val;
    },


    handleSelectionChange(val) {
      this.filteredData2 = val;
    },
    getList() {

      listEquipment2(this.currentPage, this.pageSize).then((res) => {
        this.data = res.data;
        console.log(res);
        this.filteredData = res.data.data.list;
        this.total = res.data.data.total;
      });
    },
    handleCurrentChange(val) {
      this.page = val;
      this.page1 = val;
      this.currentPage = val;
      this.proPage = val;
      this.getList();
      this.init();
      this.groupSearch();
    },

    handleSizeChange(size) {
      this.size = size;
      this.size1 = size;
      this.pageSize = size;
      this.sizes = size;
      console.log(size);
      this.init();
      this.groupSearch();
      this.getList();
      this.getProject();
    },
    singleElection(index) {
      console.log(index);
      this.templateSelection = index;
      console.log(this.templateSelection);
    },
    handleRadioSelect(row) {
      console.log(row);
      let index = thi.execution.records.indexof(row);
      this.handleRadioSelect(index);
    },
    ruleSumit() {
      this.rule = false;
      this.scheme.patrolSchemeRule = this.templateSelection.executionId;

    },
    classSubmit() {
      this.group = false;
      this.scheme.patrolSchemeClass = this.templateSelection.className;
    },
    clerkSubmit() {
      console.log(this.templateSelection);
      this.clerk = false;
      this.scheme.patrolSchemePerson = this.templateSelection.userName;
    },
    groupSearch() {
      classList(this.page1, this.size1, this.condition)
        .then((res) => {
          console.log(res.data);
          this.classList = res.data;
        })
        .catch((res) => { });
    }, user() {
      listUser(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        console.log(response.rows);
      }
      );
    },

    classSearch() {
      this.groupSearch();
    },
    handleConfirm() {
      this.device = false;
      for (let i = 0; i < this.mulitiSelect.length; i++) {

      }
      for (let i = 0; i < this.filteredData2.length; i++) {
        this.tableData.push({
          id: this.tableData.length + 1,
          numbering: this.filteredData2[i].code,
          name: this.filteredData2[i].name,
          model: this.filteredData2[i].specifications,
          type: this.filteredData2[i].deviceType,
          brand: this.filteredData2[i].brand,
          department: this.filteredData2[i].useDepartments,
          location: this.filteredData2[i].storageLocation,
          isCritical: '1',
          isScan: '1',
          reference: 1,
          quantity: 1,
          tombstone: 0,
          estimate: 2,
        });
      }
      this.$refs.registTable2.clearSelection();
      // this.$refs.refIns.clearSelection();
      this.project = false;


    },
    handleCancel() {
      this.filteredData2 = [];
      this.device = false;
    },
    handleView(row) {

      this.tableData.splice(row, 1);
    },
    confirmForm() {

      console.log(this.selectChange);
      if (this.validateForm()) {
      patroladd(this.scheme).then((res) => {
        for (let i = 0; i < this.mulitiSelect.length; i++) {
          this.detail.inspectionCode = this.mulitiSelect[i].code;
          console.log("mul", this.mulitiSelect[i]);
          for (let j = 0; j < this.tableData.length; j++) {
            this.detail.deviceCode = this.tableData[j].numbering;
            this.detail.isScan = this.tableData[j].isScan;
            this.detail.isCritical = this.tableData[j].isCritical;
            console.log("table", this.tableData[j]);

          }
          detailadd(this.detail).then((res) => {

          })
        }
        for (let i = 0; i < this.documents.length; i++) {
          this.document.uploader = this.$store.state.user.name;
          this.document.uploadDate = new Date().toLocaleDateString();
          this.document.size = this.documents[i].size;
          this.document.name = this.documents[i].name;
          upload(this.document).then((res) => {

          })
        }

        this.scheme.selectChange=this.selectChange
        if (this.scheme.patrolSchemeType == '已审核') {
          taskadd(this.scheme).then((res) => {
            this.$message({
              type: 'success',
              message: '添加成功!'

            });


          }).catch((error => {
            this.$message({
              type: 'error',
              message: '添加失败!'
            });
          }))
        }

      }).catch((error => {
        this.$message({
          type: 'success',
          message: '添加失败!'
        });
      }));console.log(this.detail);
    }else{
      this.$message({
        type: 'error',
        message: '请填写完整信息!'
      });
    }
      
    },
    handleUploadSuccess2(file, fileList) {
      this.documents.push({
        name: file.name,
        uploadDate: new Date().toLocaleDateString(),
        uploader: "当前用户",
        size: file.size + " KB",
      });
    },
    beforeUpload(file) {
      const isLt10M = file.size / 1024 / 1024 < 10;

      if (!isLt10M) {
        this.$message.error("上传文件大小不能超过 10MB!");
      }
      return isLt10M;
    }, removeRow2(index) {
      this.childDevices.splice(index, 1);
    },
    handleSelectionChange2(val) {
      this.multipleSelection = val;
    },
    removeSelectedRows3() {
      this.documents = this.documents.filter(
        (item) => !this.multipleSelection.includes(item)
      );
    },
    removeRow3(index) {
      this.documents.splice(index, 1);
    },
    closeForm() {
      this.$router.clearfix;
      this.$router.go(-1);
    }
  },
};
</script>
<style>
.position {
  margin-top: 20%;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  text-align: center;
  z-index: 2;
}

.box-card {
  margin-bottom: 40px;
  margin-left: 20px;
  margin-top: 10px;
  width: 95%;
}

.clearfix::after {
  content: "";
  display: block;
  clear: both;
}
</style>
